class CommentsController < ApplicationController
  def create
    @comment = Comment.new(params[:comment])
    @comment.user_id = current_user.id
    @comment.leechdom_id = params[:comment][:leechdom_id]
    if @comment.save
      flash[:notice] = '评论添加成功。'
      uri = session[:original_uri]
      session[:original_uri] = nil
      redirect_to(uri)
    else
      flash[:notice] = '评论出错。'
      uri = session[:original_uri]
      session[:original_uri] = nil
      redirect_to(uri)
    end
  end
  
  def destroy
    @comment = Comment.find(params[:id])
    @comment.destroy
    flash[:notice] = '评论删除成功。'
    uri = session[:original_uri]
    session[:original_uri] = nil
    redirect_to(uri)
  end
end
